// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause

#ifndef CONNECTIONHANDLER_H
#define CONNECTIONHANDLER_H

#include <QBluetoothLocalDevice>

#include <qqml.h>

#include <QObject>

class ConnectionHandler : public QObject
{
    Q_OBJECT

    Q_PROPERTY(bool alive READ alive NOTIFY deviceChanged)                      //alive没有对应变量，而对应一个返回值。
    Q_PROPERTY(QString name READ name NOTIFY deviceChanged)
    Q_PROPERTY(QString address READ address NOTIFY deviceChanged)
    Q_PROPERTY(bool requiresAddressType READ requiresAddressType CONSTANT)
    Q_PROPERTY(QUrl cur_dir READ curDir CONSTANT)   //仿requiresAddressType.

    QML_ELEMENT     //将C++类型，注册到QML。
public:
    explicit ConnectionHandler(QObject *parent = nullptr);

    bool alive() const;
    bool requiresAddressType() const;
    QString name() const;
    QString address() const;
    QUrl curDir() const;
    QUrl save_dir;
    //QString save_dir;
    //void do_it(void);

signals:
    void deviceChanged();   //它是上面3个属性指定的NOTIFY函数，不是默认的propertyChanged。

private slots:
    void hostModeChanged(QBluetoothLocalDevice::HostMode mode);

public slots:
    void do_it(void);
private:
    QBluetoothLocalDevice m_localDevice;
};

#endif // CONNECTIONHANDLER_H
